<?php
/**
 * Created by PhpStorm.
 * Author: kaodou
 * Date: 2017/10/17
 * Time: 15:07
 */
namespace App\Http\Admin\Photo\Controllers;

use Framework\BaseClass\Http\Admin\Controller;
use App\Http\Admin\Website\Models\Menu;
use App\Http\Admin\Photo\Models\Photo;
use App\Http\Admin\Category\Models\Category;
use Illuminate\Support\Facades\Storage;
use App\Engine\Func;

class IndexController extends Controller
{
    public function upload()
    {
//        $request = request();
//        $path = $request->file('file')->store('avatars');

        $type           = request('path_type', 0 );
        $file_name      = request('file_name', 'file');

//        $file_type      = Func::getImgUploadConfig( 'type', $type );

        if($upload_result  = Func::imgUpload( $type, $file_name ) and $upload_result['status']){
//            return json_encode(['statusCode'=>200,'message'=>'ok','filename'=>'sdagfasgd']);
            return $this->ajaxSuccess('图片上传成功',$upload_result);
        }else{
            return $this->ajaxSuccess('图片上传失败');
        }

//        return $this->jsonReturn($result);

    }

    private function savePhoto($path,$album_id = 0)
    {
        $saveData = ['path'=>$path, 'album_id'=>$album_id];

        $photo = new Photo();

        return $photo->addPhoto($saveData);
    }

}